package com.example.demo02.utils;

import com.example.demo02.utils.ResponseData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(NullPointerException.class)
    public ResponseData exception(NullPointerException nullPointerException) {
        return new ResponseData("500","空指针异常", false, null);
    }

    @ExceptionHandler(IndexOutOfBoundsException.class)
    public ResponseData exception(IndexOutOfBoundsException indexOutOfBoundsException) {
        return new ResponseData("500","数组下标越界异常", false, null);
    }

    @ExceptionHandler(Exception.class)
    public ResponseData exception(Exception exception) {
        return new ResponseData("500",exception.getMessage(), false, null);
    }

}
